﻿using System;
using System.Collections.Generic;
using Microsoft.Xna.Framework.Content;
using FlanProjectData.GameObjects;
using FlanProjectData.Maps;
using FlanProjectData.Helpers;

namespace FlanProjectData.Characters
{
    public class NonPlayableCharacter : Character
    {
        private static Logger logger = new Logger("NonPlayableCharacter", Log_Type.DEBUG);

		//public int idNonPlayableCharacter { get; set; }
		// public String Name { get; set; } In Mother-Class
		public int IdEvent { get; set; }
		[ContentSerializerIgnore]
		public int IndexQuest { get; set; } 
        public  List<Quest> ListQuest;
        //public List<int> lstIdSprite { get; set; }		// Contains all id of sprite concerning this PNJ.

        /** Gestion des événements.
         */
        public event EventHandler<Event> evt;


        public NonPlayableCharacter()
        {
            //Quest q = new Quest();
            //q.checkpoint.Add(3);
            //q.dialogList.Add("J'ai une quete a vous proposer");
            //this.listQuest.Add(q);

            IndexQuest = 0;
        }

        // NPC give the quest to the players
        // The quest begin
        public Quest getQuest()
        {
            if (IndexQuest < ListQuest.Count)
            {
                IndexQuest++;
                this.ListQuest[IndexQuest - 1].startQuest();
                return this.ListQuest[IndexQuest - 1];
            }
            else
            {
                return null;
            }
        }

        public bool canIGiveAQuest(int collisionNumber)
        {
			try
			{
				if (this.IndexQuest < this.ListQuest.Count && this.ListQuest[IndexQuest].isCollision(collisionNumber)) return true;
				else return false;
			}
			catch (Exception e)
			{
				logger.Info(e.Message);
				return false;
			}
        }

        /* Génére un évènement lorsqu'un joueur entre en contact avec le NPC */
        public void YouContactMe()
        {
            logger.Debug("Event Raise, Someone contact me : " + this.IdEvent);
            if (this.evt != null)
            {
                evt(this, new Event { msg = this.getQuest().GetQuestInfomation() });
            }
        }

        public void AddQuest(Quest q)
        {
            if (ListQuest == null)
                this.ListQuest = new List<Quest>();
            this.ListQuest.Add(q);
        }

        public bool IHaveThisQuest(int questID)
        {
            foreach (Quest q in ListQuest)
            {
                if (q.IdQuest == questID)
                    return true;
            }
            return false;
        }
    }
}
